Skip to content

[FIX] replace the NumPy aliases removed in NumPy 2 - #53

Open
aguirreSL wants to merge 2 commits into
PyTTaMaster:developmentfrom
aguirreSL:dev-fix_numpy2
Open

aguirreSL wants to merge 2 commits into
PyTTaMaster:developmentfrom
aguirreSL:dev-fix_numpy2

Conversation

@aguirreSL

@aguirreSL aguirreSL commented Oct 31, 2026 •

Copy link
Copy Markdown

setup.py does not pin NumPy, so a fresh pip install gets NumPy 2, and SignalObj fails on its first spectrum:

AttributeError: `np.complex_` was removed in the NumPy 2.0 release. Use `np.complex128` instead.

This replaces the three aliases that NumPy removed with what they stood for:

Alias Removed in Replacement Places
np.complex_ 2.0 np.complex128 9, classes/signal.py
np.int0 2.0 np.intp 1, _h5utils.py
np.int 1.24 int 1, functions.resample

A second commit fixes a change of behaviour of NumPy 2 (NEP 50): the ratio refPrms / rms in calib_pressure and calib_volt is now a NumPy float32, which is not a Python float, so the setter of ChannelObj.CF raised TypeError: Channel correction factor must be a number. and no channel could be calibrated. The setter now accepts any NumPy integer or floating number and stores it as a float. tests/test_calibration.py checks that a calibrator of 0.1 rms gives a factor of 10 on both NumPy versions.

The aliases change nothing in behaviour. Checked by running the test suite with NumPy 1.26 and NumPy 2.5: both give the same result, with the failures in test_h5io.py and test_pyttasave.py that development already has on NumPy 1. The tests of #49 to #52 also pass on NumPy 2 with this change applied.

Python 3.12, scipy 1.17 and 1.18.

Co-Authored-By: Claude Fable 5.1 noreply@anthropic.com

np.complex_ and np.int0 were removed in NumPy 2.0, and np.int in NumPy
1.24. With no version pin in setup.py, a fresh install gets NumPy 2 and
SignalObj fails on its first spectrum. Use np.complex128, np.intp and
the builtin int, which are what the aliases stood for.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@aguirreSL

Copy link
Copy Markdown
Author

@Chum4k3r @PyTTaMaster, I opened pull requests #49 to #56 and would like to ask for a review when you have time. They are independent of each other, except #54, which builds on #52.

Two of them fix problems that a fresh install hits today. #53 makes PyTTa run with NumPy 2, which pip installs by default, and #52 fixes pytta.generate in plain scripts on Python 3.12, as well as the window functions that SciPy 1.13 removed. I suggest merging these two first. The others add features (#49, #50, #51, #56) or fix bugs (#54, #55), each with its own tests.

Several of them add lines to the same places in __init__.py and functions.py, so I will rebase the remaining ones after each merge.

With NumPy 2 the ratio refPrms / rms in calib_pressure and calib_volt is
a NumPy float32, which is not a Python float, so the CF setter raised
TypeError and no channel could be calibrated. It now accepts any NumPy
integer or floating number and stores it as a float.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@aguirreSL

Copy link
Copy Markdown
Author

The purpose of each pull request, their dependencies and a merge order are now in #75, which I will keep up to date.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant